/* eslint-disable */
const webpack = require("webpack");
const HtmlwebpackPlugin = require("html-webpack-plugin");
const ForkTsCheckerWebpackPlugin = require("fork-ts-checker-webpack-plugin");
// const CopyWebpackPlugin = require("copy-webpack-plugin");
// const ESLintPlugin = require("eslint-webpack-plugin");
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const { VueLoaderPlugin } = require("vue-loader");
const path = require("path");


var renderer = {
  target: "electron-renderer",
  entry: path.join(__dirname, "../src/renderer/renderer.ts"),
  devtool: "inline-source-map",
  plugins: [
    // 请确保引入这个插件！
    new VueLoaderPlugin(),
    // new ESLintPlugin({
    //   overrideConfigFile: path.join(__dirname, "renderer.eslintrc"),
    //   fix: false,
    //   extensions: [".js", ".jsx", ".vue", ".ts", ".tsx"],
    //   cache: false,
    //   emitWarning: false,
    //   emitError: false,
    //   formatter: undefined
    // }),
    new HtmlwebpackPlugin({
      title: "main",
      filename: "main.html",
      template: "./src/renderer/index.html"
    }),
    new MiniCssExtractPlugin(),
    new ForkTsCheckerWebpackPlugin({
      // eslint: {
      //   enabled: false,
      //   files: "./src/**/*.ts",
      //   options: {
      //     overrideConfigFile: path.join(__dirname, "../config/renderer.eslintrc"),
      //     fix: false,
      //     extensions: [".js", ".jsx", ".vue", ".ts", ".tsx"],
      //     cache: true,
      //     emitWarning: false,
      //     emitError: false,
      //     formatter: undefined
      //   }
      // },
      typescript: {
        configFile: path.join(__dirname, "tsconfig.json"),
        extensions: {
          vue: {
            enabled: true,
            compiler: "vue-template-compiler"
          }
        }
      }
    })
  ],
  module: {
    rules: [
      {
        test: /\.ts?$/,
        use: [
          {
            loader: "cache-loader"
          },
          {
            loader: "ts-loader",
            options: {
              configFile: path.join(__dirname, "tsconfig.json"),
              transpileOnly: true,
              appendTsSuffixTo: ["\\.vue$"],
              happyPackMode: true
            }
          }
        ]
      },
      {
        test: /\.tsx$/,
        use: [
          {
            loader: "cache-loader"
          },
          {
            loader: "ts-loader",
            options: {
              configFile: path.join(__dirname, "tsconfig.json"),
              transpileOnly: true,
              appendTsSuffixTo: ["\\.vue$"],
              happyPackMode: true
            }
          }

          // {
          //   loader: "thread-loader"
          // },
          // {
          //   loader: "ts-loader"
          // }
        ]
      },
      {
        test: /\.vue$/,
        use: [
          {
            loader: "cache-loader",
            options: {}
          },
          {
            loader: "vue-loader",
            options: {
              compilerOptions: {
                whitespace: "condense"
              }
            }
          }
        ]
      },
      {
        test: /\.(js|vue|ts|tsx|jsx)$/,
        enforce: "pre",
        exclude: /node_modules/,
        use: [
          {
            loader: "eslint-loader",
            options: {
              // overrideConfigFile: path.join(__dirname, "renderer.eslintrc"),
              fix: false,
              extensions: [".js", ".jsx", ".vue", ".ts", ".tsx"],
              cache: true,
              emitWarning: false,
              emitError: false,
              formatter: undefined
            }
          }
        ]
      },
      // {
      //   test: /\.m?jsx?$/,
      //   exclude: function() {
      //     /* omitted long function */
      //   },
      //   use: [
      //     {
      //       loader: "cache-loader",
      //       options: {}
      //     },
      //     {
      //       loader: "thread-loader",
      //       options: {}
      //     },
      //     {
      //       loader: "babel-loader",
      //       options: {}
      //     }
      //   ]
      // },
      {
        test: /\.pug$/,
        oneOf: [
          // 这条规则应用到 Vue 组件内的 `<template lang="pug">`
          {
            resourceQuery: /^\?vue/,
            use: [
              {
                loader: "pug-plain-loader"
              }
            ]
          },
          // 这条规则应用到 JavaScript 内的 pug 导入
          {
            use: [
              {
                loader: "pug-plain-loader"
              },
              {
                loader: "raw-loader"
              }
            ]
          }
        ]
      },
      {
        test: /\.(png|jpe?g|gif|webp)(\?.*)?$/,
        use: [
          {
            loader: "url-loader",
            options: {
              limit: 40960,
              fallback: {
                loader: "file-loader",
                options: {
                  name: "assets/images/[name].[hash:8].[ext]"
                }
              }
            }
          }
        ]
      },
      {
        test: /\.(svg)(\?.*)?$/,
        use: [
          /* config.module.rule('svg').use('file-loader') */
          {
            loader: "file-loader",
            options: {
              name: "assets/images/[name].[hash:8].[ext]"
            }
          }
        ]
      },
      {
        test: /\.(mp4|webm|ogg|mp3|wav|flac|aac)(\?.*)?$/,
        use: [
          {
            loader: "url-loader",
            options: {
              limit: 4096,
              fallback: {
                loader: "file-loader",
                options: {
                  name: "assets/media/[name].[hash:8].[ext]"
                }
              }
            }
          }
        ]
      },
      {
        test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/i,
        use: [
          {
            loader: "url-loader",
            options: {
              limit: 4096,
              fallback: {
                loader: "file-loader",
                options: {
                  name: "assets/fonts/[name].[hash:8].[ext]"
                }
              }
            }
          }
        ]
      },
      {
        test: /\.css$/,
        oneOf: [
          /* config.module.rule('css').oneOf('vue-modules') */
          {
            resourceQuery: /module/,
            use: [
              /* config.module.rule('css').oneOf('vue-modules').use('extract-css-loader') */
              {
                loader: MiniCssExtractPlugin.loader,
                options: {
                  hmr: false,
                  publicPath: "../"
                }
              },
              /* config.module.rule('css').oneOf('vue-modules').use('css-loader') */
              {
                loader: "css-loader",
                options: {
                  sourceMap: false,
                  importLoaders: 2,
                  modules: {
                    localIdentName: "[name]_[local]_[hash:base64:5]"
                  }
                }
              }
              // ,
              /* config.module.rule('css').oneOf('vue-modules').use('postcss-loader') */
              // {
              //   loader: 'postcss-loader',
              //   options: {
              //     sourceMap: false,
              //     plugins: [
              //       function () { /* omitted long function */ }
              //     ]
              //   }
              // }
            ]
          },
          /* config.module.rule('css').oneOf('vue') */
          {
            resourceQuery: /\?vue/,
            use: [
              /* config.module.rule('css').oneOf('vue').use('extract-css-loader') */
              {
                loader: MiniCssExtractPlugin.loader,
                options: {
                  // hmr: false,
                  // publicPath: "../"
                }
              },
              /* config.module.rule('css').oneOf('vue').use('css-loader') */
              {
                loader: "css-loader",
                options: {
                  sourceMap: false,
                  importLoaders: 2
                }
              }
              // ,
              // /* config.module.rule('css').oneOf('vue').use('postcss-loader') */
              // {
              //   loader: 'postcss-loader',
              //   options: {
              //     sourceMap: false,
              //     plugins: [
              //       function () { /* omitted long function */ }
              //     ]
              //   }
              // }
            ]
          },
          /* config.module.rule('css').oneOf('normal-modules') */
          {
            test: /\.module\.\w+$/,
            use: [
              /* config.module.rule('css').oneOf('normal-modules').use('extract-css-loader') */
              {
                loader: MiniCssExtractPlugin.loader,
                options: {
                  // hmr: false,
                  // publicPath: "../"
                }
              },
              /* config.module.rule('css').oneOf('normal-modules').use('css-loader') */
              {
                loader: "css-loader",
                options: {
                  sourceMap: false,
                  importLoaders: 2,
                  modules: {
                    localIdentName: "[name]_[local]_[hash:base64:5]"
                  }
                }
              }
              // ,
              // {
              //   loader: 'postcss-loader',
              //   options: {
              //     sourceMap: false,
              //     plugins: [
              //       function () { /* omitted long function */ }
              //     ]
              //   }
              // }
            ]
          },
          {
            use: [
              {
                loader: MiniCssExtractPlugin.loader,
                options: {
                  // hmr: false,
                  // publicPath: "../"
                }
              },
              {
                loader: "css-loader",
                options: {
                  sourceMap: false,
                  importLoaders: 2
                }
              }
              // ,
              // {
              //   loader: 'postcss-loader',
              //   options: {
              //     sourceMap: false,
              //     plugins: [
              //       function () { /* omitted long function */ }
              //     ]
              //   }
              // }
            ]
          }
        ]
      },
      {
        test: /\.scss$/,
        oneOf: [
          /* config.module.rule('scss').oneOf('vue-modules') */
          {
            resourceQuery: /module/,
            use: [
              /* config.module.rule('scss').oneOf('vue-modules').use('extract-css-loader') */
              {
                loader: MiniCssExtractPlugin.loader,
                options: {
                  // hmr: false,
                  // publicPath: "../"
                }
              },
              /* config.module.rule('scss').oneOf('vue-modules').use('css-loader') */
              {
                loader: "css-loader",
                options: {
                  sourceMap: false,
                  importLoaders: 2,
                  modules: {
                    localIdentName: "[name]_[local]_[hash:base64:5]"
                  }
                }
              },
              /* config.module.rule('scss').oneOf('vue-modules').use('postcss-loader') */
              // {
              //   loader: '/mnt/d/vuetest/testv2/node_modules/postcss-loader/src/index.js',
              //   options: {
              //     sourceMap: false,
              //     plugins: [
              //       function () { /* omitted long function */ }
              //     ]
              //   }
              // },
              /* config.module.rule('scss').oneOf('vue-modules').use('sass-loader') */
              {
                loader: "sass-loader",
                options: {
                  sourceMap: false
                }
              }
            ]
          },
          /* config.module.rule('scss').oneOf('vue') */
          {
            resourceQuery: /\?vue/,
            use: [
              /* config.module.rule('scss').oneOf('vue').use('extract-css-loader') */
              {
                loader: MiniCssExtractPlugin.loader,
                options: {
                  // hmr: false,
                  // publicPath: "../"
                }
              },
              /* config.module.rule('scss').oneOf('vue').use('css-loader') */
              {
                loader: "css-loader",
                options: {
                  sourceMap: false,
                  importLoaders: 2
                }
              },
              /* config.module.rule('scss').oneOf('vue').use('postcss-loader') */
              // {
              //   loader: '/mnt/d/vuetest/testv2/node_modules/postcss-loader/src/index.js',
              //   options: {
              //     sourceMap: false,
              //     plugins: [
              //       function () { /* omitted long function */ }
              //     ]
              //   }
              // },
              /* config.module.rule('scss').oneOf('vue').use('sass-loader') */
              {
                loader: "sass-loader",
                options: {
                  sourceMap: false
                }
              }
            ]
          },
          /* config.module.rule('scss').oneOf('normal-modules') */
          {
            test: /\.module\.\w+$/,
            use: [
              /* config.module.rule('scss').oneOf('normal-modules').use('extract-css-loader') */
              {
                loader: MiniCssExtractPlugin.loader,
                options: {
                  // hmr: false,
                  // publicPath: "../"
                }
              },
              /* config.module.rule('scss').oneOf('normal-modules').use('css-loader') */
              {
                loader: "css-loader",
                options: {
                  sourceMap: false,
                  importLoaders: 2,
                  modules: {
                    localIdentName: "[name]_[local]_[hash:base64:5]"
                  }
                }
              },
              /* config.module.rule('scss').oneOf('normal-modules').use('postcss-loader') */
              // {
              //   loader: '/mnt/d/vuetest/testv2/node_modules/postcss-loader/src/index.js',
              //   options: {
              //     sourceMap: false,
              //     plugins: [
              //       function () { /* omitted long function */ }
              //     ]
              //   }
              // },
              /* config.module.rule('scss').oneOf('normal-modules').use('sass-loader') */
              {
                loader: "sass-loader",
                options: {
                  sourceMap: false
                }
              }
            ]
          },
          /* config.module.rule('scss').oneOf('normal') */
          {
            use: [
              /* config.module.rule('scss').oneOf('normal').use('extract-css-loader') */
              {
                loader: MiniCssExtractPlugin.loader,
                options: {
                  // hmr: false,
                  // publicPath: "../"
                }
              },
              /* config.module.rule('scss').oneOf('normal').use('css-loader') */
              {
                loader: "css-loader",
                options: {
                  sourceMap: false,
                  importLoaders: 2
                }
              },
              /* config.module.rule('scss').oneOf('normal').use('postcss-loader') */
              // {
              //   loader: '/mnt/d/vuetest/testv2/node_modules/postcss-loader/src/index.js',
              //   options: {
              //     sourceMap: false,
              //     plugins: [
              //       function () { /* omitted long function */ }
              //     ]
              //   }
              // },
              /* config.module.rule('scss').oneOf('normal').use('sass-loader') */
              {
                loader: "sass-loader",
                options: {
                  sourceMap: false
                }
              }
            ]
          }
        ]
      },
      {
        test: /\.sass$/,
        oneOf: [
          /* config.module.rule('sass').oneOf('vue-modules') */
          {
            resourceQuery: /module/,
            use: [
              /* config.module.rule('sass').oneOf('vue-modules').use('extract-css-loader') */
              {
                loader: MiniCssExtractPlugin.loader,
                options: {
                  // hmr: false,
                  // publicPath: "../"
                }
              },
              /* config.module.rule('sass').oneOf('vue-modules').use('css-loader') */
              {
                loader: "css-loader",
                options: {
                  sourceMap: false,
                  importLoaders: 2,
                  modules: {
                    localIdentName: "[name]_[local]_[hash:base64:5]"
                  }
                }
              },
              /* config.module.rule('sass').oneOf('vue-modules').use('postcss-loader') */
              // {
              //   loader: '/mnt/d/vuetest/testv2/node_modules/postcss-loader/src/index.js',
              //   options: {
              //     sourceMap: false,
              //     plugins: [
              //       function () { /* omitted long function */ }
              //     ]
              //   }
              // },
              /* config.module.rule('sass').oneOf('vue-modules').use('sass-loader') */
              {
                loader: "sass-loader",
                options: {
                  sourceMap: false,
                  sassOptions: {
                    indentedSyntax: true
                  }
                }
              }
            ]
          },
          /* config.module.rule('sass').oneOf('vue') */
          {
            resourceQuery: /\?vue/,
            use: [
              /* config.module.rule('sass').oneOf('vue').use('extract-css-loader') */
              {
                loader: MiniCssExtractPlugin.loader,
                options: {
                  // hmr: false,
                  // publicPath: "../"
                }
              },
              /* config.module.rule('sass').oneOf('vue').use('css-loader') */
              {
                loader: "css-loader",
                options: {
                  sourceMap: false,
                  importLoaders: 2
                }
              },
              /* config.module.rule('sass').oneOf('vue').use('postcss-loader') */
              // {
              //   loader: '/mnt/d/vuetest/testv2/node_modules/postcss-loader/src/index.js',
              //   options: {
              //     sourceMap: false,
              //     plugins: [
              //       function () { /* omitted long function */ }
              //     ]
              //   }
              // },
              /* config.module.rule('sass').oneOf('vue').use('sass-loader') */
              {
                loader: "sass-loader",
                options: {
                  sourceMap: false,
                  sassOptions: {
                    indentedSyntax: true
                  }
                }
              }
            ]
          },
          /* config.module.rule('sass').oneOf('normal-modules') */
          {
            test: /\.module\.\w+$/,
            use: [
              /* config.module.rule('sass').oneOf('normal-modules').use('extract-css-loader') */
              {
                loader: MiniCssExtractPlugin.loader,
                options: {
                  // hmr: false,
                  // publicPath: "../"
                }
              },
              /* config.module.rule('sass').oneOf('normal-modules').use('css-loader') */
              {
                loader: "css-loader",
                options: {
                  sourceMap: false,
                  importLoaders: 2,
                  modules: {
                    localIdentName: "[name]_[local]_[hash:base64:5]"
                  }
                }
              },
              /* config.module.rule('sass').oneOf('normal-modules').use('postcss-loader') */
              // {
              //   loader: '/mnt/d/vuetest/testv2/node_modules/postcss-loader/src/index.js',
              //   options: {
              //     sourceMap: false,
              //     plugins: [
              //       function () { /* omitted long function */ }
              //     ]
              //   }
              // },
              /* config.module.rule('sass').oneOf('normal-modules').use('sass-loader') */
              {
                loader: "sass-loader",
                options: {
                  sourceMap: false,
                  sassOptions: {
                    indentedSyntax: true
                  }
                }
              }
            ]
          },

          /* config.module.rule('sass').oneOf('normal') */
          {
            use: [
              /* config.module.rule('sass').oneOf('normal').use('extract-css-loader') */
              {
                loader: MiniCssExtractPlugin.loader,
                options: {
                  // hmr: false,
                  // publicPath: "../"
                }
              },
              /* config.module.rule('sass').oneOf('normal').use('css-loader') */
              {
                loader: "css-loader",
                options: {
                  sourceMap: false,
                  importLoaders: 2
                }
              },
              /* config.module.rule('sass').oneOf('normal').use('postcss-loader') */
              // {
              //   loader: '/mnt/d/vuetest/testv2/node_modules/postcss-loader/src/index.js',
              //   options: {
              //     sourceMap: false,
              //     plugins: [
              //       function () { /* omitted long function */ }
              //     ]
              //   }
              // },
              /* config.module.rule('sass').oneOf('normal').use('sass-loader') */
              {
                loader: "sass-loader",
                options: {
                  sourceMap: false,
                  sassOptions: {
                    indentedSyntax: true
                  }
                }
              }
            ]
          }
        ]
      }
    ]
  },
  resolve: {
    extensions: [
      ".tsx",
      ".ts",
      ".mjs",
      ".js",
      ".jsx",
      ".vue",
      ".json",
      ".wasm"
    ],
    alias: {
      "@": "./src/renderer",
      vue$: "vue/dist/vue.esm.js",
      router: "vue-router/dist/vue-router.js"
    }
  },
  node: {
    setImmediate: false,
    process: "mock",
    dgram: "empty",
    fs: "empty",
    net: "empty",
    tls: "empty",
    child_process: "empty"
  },
  output: {
    path: path.resolve(__dirname, "../build"),
    filename: "renderer-[hash].js"
  }
};

module.exports = renderer;
